﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.20/dist/css/layui.css" rel="stylesheet">
</head>
<body>

    <div class="layui-side" style="margin-top: 30px;margin-left: 100px;">
        <div id="tree">
        </div>
    </div>
    <div class="layui-body" style="margin-top: 50px;margin-left: 100px;">

        <input type="checkbox" name="BBB" value="新增">新增
        <input type="checkbox" name="BBB" value="查询">查询
        <input type="checkbox" name="BBB" value="删除">删除
        <input type="checkbox" name="BBB" value="修改">修改
        <input type="checkbox" name="BBB" value="打印">打印
        <input type="checkbox" name="BBB" value="导入">导入

        <div>
            <button class="layui-btn" id="btn" style="margin-top: 20px;" onclick="add()">添加</button>
        </div>


    </div>
    <script>
        var pid = "";
        layui.use(function () {
            var form = layui.form;
            var layer = layui.layer;
            var tree = layui.tree;
            var layer = layui.layer;
            var element = layui.element;
            var datas = [];
            var cascader = layui.cascader;
            var dropdown = layui.dropdown;
            var util = layui.util;

            $(function () {
                treeList1()
            })
            function treeList1() {
                $.ajax({

                    url: "http://localhost:5018/api/Users/SearchRole",
                    type: "get",
                    async: true,
                    success: function (res) {
                        console.log(res)
                        datas = res.data;
                        tree.render({
                            elem: "#tree",
                            data: datas,
                            //showLine: false, // 是否开启连接线
                            click: function (res) {
                                pid = res.data.value;
                                console.log(pid)

                            }
                        });

                    }

                });

            };

        })

        function add() {
            var data = {
                roleId: pid,
                proname: $("[name=BBB]:checked").map(function () {
                    return this.value
                }).get().join(","),


            }
            console.log(data)
            $.ajax({
                url: "http://localhost:5018/api/Users/PermissionRoleAdd",
                type: 'post',
                data: JSON.stringify(data),
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    if (res.code > 0) {
                        layer.msg(res.messege);
                    }
                    else {
                        layer.msg(res.messege);
                    }
                }
            })

        }
    </script>
</body>
</html>

